package com.csdj.t309springboot.service;
import com.csdj.t309springboot.common.CacheConstant;
import com.csdj.t309springboot.entity.BlindBox;
import com.csdj.t309springboot.mapper.BlindBoxMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
 * <p>
 * 盲盒表 服务实现类
 * </p>
 *
 * @author 谭湛宇
 * @since 2022-01-14
 */
@Service
public class BlindBoxService extends ServiceImpl<BlindBoxMapper, BlindBox> implements IBlindBoxService {
    @Resource
    private BlindBoxMapper blindBoxMapper;
    @Resource
    private RedisService redisService;

    public List<Integer> getBlindBoxByJsId(Integer jsId) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("bb_js_id",jsId);
        map.put("bb_user_id",redisService.getObject(CacheConstant.HEADER_UID));
        List<BlindBox> list = blindBoxMapper.selectByMap(map);
        List<Integer> zong = new ArrayList<Integer>();
        for(Integer i = 0 ; i < 9 ; i++){
            zong.add(i);
        }
        List<Integer> a = new ArrayList<Integer>();
        for(BlindBox b : list){
            a.add(b.getJigsawPuzzleId());
        }
        zong.removeAll(a);
        if(zong.size()>0){
            return zong;
        }
        return null;
    }
    public BlindBox getBlindBoxInfo(int id){
        return blindBoxMapper.selectById(id);
    }
    public List<BlindBox> getAllBlindBox(){
        return blindBoxMapper.selectList(null);
    }

}
